package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.PDF;
import com.ruoyi.system.service.IPdfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

/**
 * PDF 文件管理控制器
 *
 * @author
 */
@RestController
@RequestMapping("/system/pdf")
public class PdfController extends BaseController {

    @Autowired
    private IPdfService pdfService;

    /**
     * 获取PDF文件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PDF pdf) {
        startPage();
        List<PDF> list = pdfService.selectPdfList(pdf);
        return getDataTable(list);
    }

    /**
     * 获取PDF详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(pdfService.selectPdfById(id));
    }

    /**
     * 新增PDF文件
     */
    @Log(title = "PDF文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PDF pdf) {
//        pdf.setCreateBy(getUsername());
        return toAjax(pdfService.insertPdf(pdf));
    }

    /**
     * 修改PDF文件
     */
    @Log(title = "PDF文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PDF pdf) {
        return toAjax(pdfService.updatePdf(pdf));
    }

    /**
     * 删除PDF文件
     */
    @Log(title = "PDF文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pdfService.deletePdfByIds(ids));
    }
}
